package com.baomidou.ant.controller;

import com.baomidou.ant.common.Result;
import com.baomidou.ant.entity.PvpMessage;
import com.baomidou.ant.service.IPvpMessageService;
import com.baomidou.ant.service.IUserBagService;
import com.baomidou.ant.service.IUserService;
import com.baomidou.ant.vo.Response.ResponseMessageListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/pvpMessage")
public class PvpMessageController {
    @Autowired
    private IPvpMessageService pvpMessageService;
    @Autowired
    private IUserService userService;

    @GetMapping("/listMessage/{enemyId}")
    public Result listMessage(@PathVariable Integer enemyId){
        QueryWrapper<PvpMessage> pvpMessageQueryWrapper =new QueryWrapper<>();
        pvpMessageQueryWrapper.eq("response_user",enemyId);
        pvpMessageQueryWrapper.eq("status","0");
        List<PvpMessage> messageList=pvpMessageService.list(pvpMessageQueryWrapper);
        ResponseMessageListVo vo=new ResponseMessageListVo();
        for(PvpMessage pvpMessage:messageList){
            vo.setRequestUser(userService.getById(pvpMessage.getRequestUser()).getUsername());
            vo.setResponseUser(userService.getById(pvpMessage.getResponseUser()).getUsername());
        }
        return Result.getSuccess().setData(vo);
    }


}
